<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
include_once ("secure_area.php");

class Product_packages extends Secure_area {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URLa
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function __construct(){
		parent::__construct();
		$this->load->model('lib_model');
		$this->load->model('admin_product_packages_model');
		$this->load->helper('boolean_helper');
	}

	public function index(){
		$this->page();
	}

	function page($params=''){
		//pagination
		$this->load->library('pagination');
		$start_row = $this->uri->segment(4);
		$limit = 20;

		if(trim($start_row) == ""){
			$start_row = 0;
		}
		$data['title'] = 'Product Packages Listing';

		if(empty($params['keyword'])){
			$config['base_url'] = site_url('admin/product_packages/page');
			$config['total_rows'] =  count($this->admin_product_packages_model->listPackages());
		}

		$data['main_content'] = 'admin/product_packages_listing';

		$config['per_page'] = $limit;
		$config['uri_segment'] = 4;

		$config['anchor_class'] = 'class="button pagi" ';
		$this->pagination->initialize($config);
		$data['pagination'] = $this->pagination->create_links();
		if((!empty($params)) && ($params['action']=='search') && (!empty($params['keyword']))){
			$data['package_qry_limited'] = $this->admin_product_packages_model->search($params['keyword']);
		}else{
			$data['package_qry_limited']=$this->admin_product_packages_model->listPackages($start_row, $limit);
		}

		$this->load->view('admin/includes/template', $data);
	}
}
